package com.woniu.apiBoss.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.apiBoss.service.ApiPriceRuleService;
import com.woniu.internalcommon.dto.ForecastPriceDTO;
import com.woniu.internalcommon.dto.PriceRule;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.request.PriceRuleIsNewRequest;
import com.woniu.internalcommon.response.ForecastPriceResponse;
import com.woniu.internalcommon.response.PriceRulePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zcnovice
 * @data 2025/7/12 下午3:15
 */
@RestController
@CrossOrigin
public class ApiPriceRuleController {

    @Autowired
    private ApiPriceRuleService priceRuleService;

    //添加计价规则
    @PostMapping( "/price-rule/add")
    public ResponseResult add(@RequestBody PriceRule priceRule){
        ResponseResult add = priceRuleService.add(priceRule);
        return add;
    }

    //编辑计价规则
    @PostMapping("/price-rule/edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule){
        ResponseResult edit = priceRuleService.edit(priceRule);
        return edit;
    }

    //查询最新的计价规则
    @GetMapping("/price-rule/get-newest-version")
    public ResponseResult<PriceRule> getNewestVersion(@RequestParam("fareType") String fareType){
        ResponseResult<PriceRule> newestVersion = priceRuleService.getNewestVersion(fareType);
        return newestVersion;
    }

//    //判断计价规则是否存在
//    @PostMapping("/price-rule/if-exists")
//    public ResponseResult<Boolean> ifPriceExists(@PathVariable("cityCode") String cityCode, @PathVariable("vehicleType") String vehicleType){
//        ResponseResult<Boolean> ifExists = servicePriceClient.ifPriceExists(cityCode,vehicleType);
//        return ifExists;
//    }

    //判断规则是不是最新的
    @PostMapping("/price-rule/is-new")
    public ResponseResult<Boolean> isNew(@RequestBody PriceRuleIsNewRequest priceRuleIsNewRequest){
        ResponseResult<Boolean> isNew = priceRuleService.isNew(priceRuleIsNewRequest);
        return isNew;
    }


    @PostMapping("/price-rule/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestParam(value = "cityCode")String cityCode,@RequestParam(value = "vehicleType")String vehicleType){
        ResponseResult<Boolean> ifExists = priceRuleService.ifExists(cityCode,vehicleType);
        return ifExists;
    }

    //计算价格-
    @PostMapping("/price-rule/calculate-price")
    public ResponseResult<Double> calculatePrice(@RequestParam Integer distance, @RequestParam Integer duration, @RequestParam String cityCode, @RequestParam String vehicleType){
        ResponseResult<Double> calculatePrice = priceRuleService.calculatePrice(distance, duration, cityCode, vehicleType);
        return calculatePrice;
    }

    //预估价格
    @PostMapping("/forecast-price")
    public ResponseResult<ForecastPriceResponse> forecast(@RequestBody ForecastPriceDTO forecastPriceDTO){
        ResponseResult<ForecastPriceResponse> forecast = priceRuleService.forecast(forecastPriceDTO);
        return forecast;
    }

    //条件查询(所有)计价规则
    @PostMapping("/price-rule/query")
    public ResponseResult<Page<PriceRule>> query(@RequestBody PriceRulePage priceRulePage){
        ResponseResult<Page<PriceRule>> query = priceRuleService.query(priceRulePage);
        return query;
    }

    //删除计价规则
    @DeleteMapping("/price-rule/delete")
    public ResponseResult delete(@RequestParam("id") Long id){
        ResponseResult delete = priceRuleService.delete(id);
        return delete;
    }

}
